-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fish completions: fix double-evaluation of commandline #2095
base: main
Are you sure you want to change the base?
Conversation
fish_completions.go
Outdated
@@ -45,7 +45,7 @@ function __%[1]s_perform_completion | |||
__%[1]s_debug "Starting __%[1]s_perform_completion" | |||
|
|||
# Extract all args except the last one | |||
set -l args (commandline -opc) | |||
set -l args (commandline -opc | string escape) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @marckhouzam
FWIW the blame for this mistake is on me, I made the suggestion to use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you fixing this.
@krobelus, do you know what needs to be done for this PR to be merged and included in the next release? |
|
The API to avoid this downside while still fixing the issue at hand has been merged in fish-shell/fish-shell#10212, which will be in the upcoming fish release. |
We capture the commandline tokens using fish's "commandline --tokenize" (-o). Given a commandline of some-cobra-command 'some argument $(123)' "$HOME" into three arguments while removing the quotes some-cobra-command some argument $(123) $HOME Later we pass "some argument $(123)" without quotes to the shell's "eval". This is wrong and causes spurious evaluation of the parenthesis as command substitution. Fix this by escaping the arguments. The upcoming fish 3.8 has a new flag, "commandline -x" which will expand variables like $HOME properly, see fish-shell/fish-shell#10212 Use that if available. Reproduce the issue by pasting the completion script at fish-shell/fish-shell#10194 (comment) to a file "grafana-manager.fish" and running function grafana-manager; end source grafana-manager.fish Then type (without pressing Enter) grafana-manager public-dashboards delete --organization-id 3 --dashboard-name "k8s (public)" <TAB> Fixes fish-shell/fish-shell#10194
eabe4e5
to
4e07448
Compare
We capture the commandline tokens using fish's "commandline --tokenize" (-o).
That function turns
into two arguments while removing the quotes
Later we pass "some argument $(123)" without quotes to the shell's
"eval". This is wrong and causes spurious evaluation of the parenthesis
as command substitution.
Fix this by escaping the arguments.
The downside of this change is that things like "$HOME" or "~" will
no longer be escaped. Changing this requires changes in fish, which
I'm working on.
Reproduce the issue by pasting the completion script at
fish-shell/fish-shell#10194 (comment)
to a file "grafana-manager.fish" and running inside
fish
Then type (without pressing Enter)
Fixes fish-shell/fish-shell#10194